//
//  SingerViewController.m
//  海角音乐
//
//  Created by dllo on 15/8/14.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "SingerViewController.h"

@interface SingerViewController ()

@end

@implementation SingerViewController

- (void)viewWillAppear:(BOOL)animated
{
    BarPlayer = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    [self.view addSubview:BarPlayer];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    CGFloat title_width = SCREEN_WIDTH*0.533333; // 200
    CGFloat title_height = SCREEN_WIDTH*0.08; // 30
    self.TitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, title_width, title_height)];
    self.TitleView.textColor = [UIColor whiteColor];
    self.TitleView.textAlignment = NSTextAlignmentCenter;
    self.TitleView.text =  @"歌手";
    self.navigationItem.titleView = self.TitleView;
    
    _singerModelArr = [[NSMutableArray alloc] init];
    
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    _singerView = [[SingerView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _singerView.singerCollection.dataSource = self;
    _singerView.singerCollection.delegate = self;    
    _singerView.singerCollection.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:_singerView];
    [_singerView.singerCollection registerClass:[SingerCollectionViewCell class] forCellWithReuseIdentifier:@"REUSEID"];
    [_singerView release];
    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.removeFromSuperViewOnHide = YES;
    HUD.labelText = @"loading...";
    [self.view addSubview:HUD];
    HUD.mode = MBProgressHUDModeIndeterminate;
    
    [self getDataForSinger];
    


    
    // Do any additional setup after loading the view.
}




- (void)getDataForSinger
{
    
    [AFN urlString:SingerUrl getAFNdata:^(id responseObject) {
        
        NSArray *dataArr = [responseObject objectForKey:@"data"];
        for (NSDictionary *dic in dataArr) {
            
            SingerModel *singerModel = [[SingerModel alloc] init];
            [singerModel setValuesForKeysWithDictionary:dic];
            [_singerModelArr addObject:singerModel];
            [singerModel release];
        }
        // 隐藏
        [HUD removeFromSuperview];
        [_singerView.singerCollection reloadData];

    }];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _singerModelArr.count;
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseID = @"REUSEID";
    SingerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseID forIndexPath:indexPath];
    SingerModel *singerModel = [_singerModelArr objectAtIndex:indexPath.row];
    [cell getDataModel:singerModel];
    return cell;
    
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    // 进入详情
    SingerDetailViewController *singerDetailVc = [[[SingerDetailViewController alloc] init] autorelease];
    SingerModel *singerModel = [_singerModelArr objectAtIndex:indexPath.row];
    singerDetailVc.singerModel = singerModel;
    [self.navigationController pushViewController:singerDetailVc animated:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
